<table class="table table-striped table-bordered bootstrap-datatable datatable" id="table_customer_order" style="margin-top:60px">
    <thead>

        <tr>
            <th>STT</th>
            <th>Tên FB</th>
            <th>Phone</th>
            <th>Mã SP</th>

            <th>Size</th>
            <th>Số Lượng</th>
            <th>Màu</th>
            <th>Ảnh</th>
            <th>Order status</th>
            <th>Ghi chú sản phẩm</th>
            <th class="gp_3">Giá<br/>(x1000 VNĐ)</th>


            <th class="gp_3">Tổng Tiền<br/>(x1000 VNĐ)</th>
            <th class="gp_3">Tổng Cọc<br/>(x1000 VNĐ)</th>
            <th class="gp_3">Thiếu<br/>(x1000 VNĐ)</th>
            <th class="gp_3">Thừa<br/>(x1000 VNĐ)</th>
            <th class="">Ghi chú đơn hàng</th>
            <th class="gp_4">Địa chỉ</th>
            <th class="gp_4">Tỉnh</th>
            <th class="gp_4">Tên thật</th>
            <th class="gp_4">Tài khoản bank</th>
            <th>Actions</th>
        </tr>
    </thead>   
    <tbody id="tbody_order_list">
        <?php
        if ($list_customer_order) {

            foreach ($list_customer_order as $customer_order) {
                $color_photo_name = $customer_order->product_color . "_" . $customer_order->product_code . "_" . $customer_order->manufacture;
                $color_photo_name = $core->convert_string_friendly($color_photo_name) . ".jpg";
                $path_color_photo = dirname(dirname(__FILE__)) . DS . "photo" . DS . "extra_photo" . DS . "thumb_extra_photo" . DS . $color_photo_name;

                if (file_exists($path_color_photo)) {
                    $src_photo = 'photo/extra_photo/' . $color_photo_name;
                    $src_photo_thumb = 'photo/extra_photo/thumb_extra_photo/' . $color_photo_name;
                } else {
                    $src_photo = 'photo/' . $customer_order->main_photo;
                    $src_photo_thumb = 'photo/thumb_photo/200_' . $customer_order->main_photo;
                }
                if ($customer_order_id != $customer_order->customer_order_id) {
                    $count++;
                    $customer_order_id = $customer_order->customer_order_id;
                    ?>
                    <tr class="tr_<?php echo $customer_order->customer_order_id; ?>">
                        <td class="center" rowspan="<?php echo $customer_order->total_product; ?>"><?php echo $count; ?></td>
                        <td class="center" rowspan="<?php echo $customer_order->total_product; ?>">
                            <?php
                            if ($customer_order->facebook_link != "") {
                                ?>
                                <a href="<?php echo $customer_order->facebook_link; ?>" target="_blank"><?php echo $customer_order->facebook_name; ?></a>
                                <?php
                            } else {
                                echo $customer_order->facebook_name;
                            }
                            ?>
                            <p></p>
                            <b>
                                <?php
                                switch ($customer_order->customer_order_status) {
                                    case 0: echo "Store";
                                        break;
                                    case 1: echo "Online";
                                        break;
                                    case 2: echo "Hàng có sẵn";
                                        break;
                                    case 3: echo "Đã nhận hàng";
                                        break;
                                    case 4: echo "Đang shipping";
                                        break;
                                    case 5: echo "Khách đã nhận";
                                        break;
                                    case 6: echo "Hết hàng";
                                        break;
                                    case 7: echo "ORDER";
                                        break;
                                    case 8: echo "Chưa chắc chắn";
                                        break;
                                    case 9: echo "Chưa xác định";
                                        break;
                                }
                                ?>
                            </b>
                            <p></p>
                             <button  class="btn btn-primary print_address_customer" type="button" rel='<?php echo $customer_order->customer_id; ?>' >Print address</button>
                        </td>

                        <td class="center" rowspan="<?php echo $customer_order->total_product; ?>">
                            <?php echo $customer_order->phone; ?>

                        </td>
                        <?php
                        if ($customer_order->link_web == "") {
                            ?>
                            <td class="center"><?php echo $customer_order->product_code; ?></td>
                            <?php
                        } else {
                            ?>
                            <td class="center"><a href="<?php echo $customer_order->link_web; ?>" target="_blank"><?php echo $customer_order->product_code; ?></a></td>
                            <?php
                        }
                        ?>


                        <td class="center"><?php echo $customer_order->product_size; ?></td>
                        <td class="center"><?php echo $customer_order->product_num; ?></td>
                        <td class="center"><?php echo $customer_order->product_color; ?></td>

                        <td class="center"><img rel="<?php echo $src_photo; ?>" class="photo_product" src="<?php echo $src_photo_thumb; ?>" width="100px"></td>
                        <td class="center">
                            <b>
                                <?php
                                switch ($customer_order->order_status) {
                                    case 0: echo "Store";
                                        break;
                                    case 1: echo "Online";
                                        break;
                                    case 2: echo "Hàng có sẵn";
                                        break;
                                    case 3: echo "Đã nhận hàng";
                                        break;
                                    case 4: echo "Đang shipping";
                                        break;
                                    case 5: echo "Khách đã nhận";
                                        break;
                                    case 6: echo "Hết hàng";
                                        break;
                                    case 7: echo "ORDER";
                                        break;
                                    case 8: echo "Chưa chắc chắn";
                                        break;
                                }
                                ?>
                            </b>
                        </td>
                        <td class="center color_status">
                            <p class="description_product_detail" data-item-id="<?php echo $customer_order->id; ?>"><?php echo nl2br(htmlspecialchars($customer_order->description)); ?></p>


                        </td>

                        <td class="center gp_3" id="td_price_<?php echo $customer_order->id; ?>"><?php if ($customer_order->order_status == 6) echo '0';else echo number_format($customer_order->product_price / 1000); ?></td>


                        <td class="center gp_3" id="td_total_price_<?php echo $customer_order->customer_order_id; ?>" rowspan="<?php echo $customer_order->total_product; ?>"><?php echo number_format($customer_order->total_order_money / 1000); ?></td>
                        <td class="center gp_3"  rowspan="<?php echo $customer_order->total_product; ?>">

                            <?php echo number_format($customer_order->total_payment / 1000); ?>
                        </td>
                        <td class="center gp_3" id="td_debit_<?php echo $customer_order->customer_order_id; ?>"  rowspan="<?php echo $customer_order->total_product; ?>"><?php
                            if ($customer_order->total_current_money < 0)
                                echo number_format($customer_order->total_current_money / 1000);
                            else
                                echo "0";
                            ?></td>
                        <td class="center gp_3" id="td_excess_cash_<?php echo $customer_order->customer_order_id; ?>" rowspan="<?php echo $customer_order->total_product; ?>">
                            <?php
                            if ($customer_order->total_current_money > 0)
                                echo number_format($customer_order->total_current_money / 1000);
                            else
                                echo "0";
                            ?>
                        </td>
                        <td class="center"
                            rowspan="<?php echo $customer_order->total_product; ?>"><?php echo $customer_order->order_description; ?>
                        </td>
                        <td class="center gp_4" rowspan="<?php echo $customer_order->total_product; ?>"><?php echo $customer_order->address; ?></td>
                        <td class="center gp_4" rowspan="<?php echo $customer_order->total_product; ?>">
                            <?php
                            if ($customer_order->province == 1)
                                echo "Ở tỉnh";
                            else
                                echo "Ở HN";
                            ?>
                        </td>
                        <td class="center gp_4" rowspan="<?php echo $customer_order->total_product; ?>"><?php echo $customer_order->name; ?></td>
                        <td class="center gp_4" rowspan="<?php echo $customer_order->total_product; ?>"><?php echo $customer_order->bank_account; ?></td>
                        <td class="center " rowspan="<?php echo $customer_order->total_product; ?>">

                        </td>
                    </tr>
                    <?php
                } else {
                    ?>
                    <tr class="tr_<?php echo $customer_order->customer_order_id; ?>">
                        <?php
                        if ($customer_order->link_web == "") {
                            ?>
                            <td class="center"><?php echo $customer_order->product_code; ?></td>
                            <?php
                        } else {
                            ?>
                            <td class="center"><a href="<?php echo $customer_order->link_web; ?>" target="_blank"><?php echo $customer_order->product_code; ?></a></td>
                            <?php
                        }
                        ?>

                        <td class="center"><?php echo $customer_order->product_size; ?></td>
                        <td class="center"><?php echo $customer_order->product_num; ?></td>
                        <td class="center"><?php echo $customer_order->product_color; ?></td>
                        <td class="center"><img rel="<?php echo $src_photo; ?>" class="photo_product" src="<?php echo $src_photo_thumb; ?>" width="100px"></td>
                        <td class="center">
                            <b>
                                <?php
                                switch ($customer_order->order_status) {
                                    case 0: echo "Store";
                                        break;
                                    case 1: echo "Online";
                                        break;
                                    case 2: echo "Hàng có sẵn";
                                        break;
                                    case 3: echo "Đã nhận hàng";
                                        break;
                                    case 4: echo "Đang shipping";
                                        break;
                                    case 5: echo "Khách đã nhận";
                                        break;
                                    case 6: echo "Hết hàng";
                                        break;
                                    case 7: echo "ORDER";
                                        break;
                                    case 8: echo "Chưa chắc chắn";
                                        break;
                                }
                                ?>
                            </b>
                        </td>
                        <td class="center color_status">
                            <p class="description_product_detail" data-item-id="<?php echo $customer_order->id; ?>"><?php echo nl2br(htmlspecialchars($customer_order->description)); ?></p>

                        </td>
                        <td class="center gp_3" id="td_price_<?php echo $customer_order->id; ?>"><?php if ($customer_order->order_status == 6) echo '0';else echo number_format($customer_order->product_price / 1000); ?></td>

                    </tr>
                    <?php
                }
            }
        }
        ?>
    </tbody>
</table>